package com.enfi.api.modules.db.service.impl;

import com.enfi.api.modules.db.base.BaseServiceImpl;
import com.enfi.api.modules.db.dao.WarningReplyRepository;
import com.enfi.api.modules.db.entity.WarningFeedback;
import com.enfi.api.modules.db.entity.WarningReply;
import com.enfi.api.modules.db.service.WarningFeedbackService;
import com.enfi.api.modules.db.service.WarningReplyService;
import com.enfi.api.modules.db.service.WarningService;
import com.enfi.api.modules.db.service.WarningSuggestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.stereotype.Service;

/**
 * 预警內容反馈回复(WarningReply)表服务实现类
 *
 * @author wind
 * @since 2020-04-07 15:59:43
 */
@Service("warningReplyService")
@NoRepositoryBean
public class WarningReplyServiceImpl extends BaseServiceImpl<WarningReplyRepository,WarningReply,Integer> implements WarningReplyService {
    @Autowired
    private WarningService warningService;
    @Autowired
    private WarningSuggestionService warningSuggestionService;
    @Autowired
    private WarningFeedbackService warningFeedbackService;

    @Override
    public boolean insert(WarningReply warningReply) {
        boolean flag=super.insert(warningReply);
        if(flag){
            warningFeedbackService.findById(warningReply.getFeedbackId()).ifPresent(v->{
                warningSuggestionService.findById(v.getSuggestionId()).ifPresent(t->{
                    warningService.findById(t.getWarningId()).ifPresent(p->{
                        p.setStatus(5);
                        warningService.save(p);
                    });
                });
            });
        }
        return flag;
    }
}